﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VOL.Core.Extensions;
using VOL.Core.Utilities;
using VOL.Entity.DomainModels;
using VOL.Entity.DomainModels.EvaluateNurseCare;
using VOL.SmartMecial.Dtos;
using VOL.SmartMecial.Infrastructure;
using VOL.SmartMecial.IServices.EvaluateNurseCare;

namespace VOL.SmartMecial.Services.EvaluateNurseCare
{
    public class PatientReCordShoowService : IPatientReCordShoowService
    {
        private readonly IBaseRepository<Patient> _patientRep;
        private readonly IBaseRepository<PatientReCordModel> _patientReCordRep;
        private readonly IBaseRepository<WardArea> _wardArea;

        public PatientReCordShoowService(IBaseRepository<Entity.DomainModels.Patient> patientRep, IBaseRepository<PatientReCordModel> patientReCordRep,IBaseRepository<WardArea> wardArea)
        {
          _patientRep = patientRep;
          _patientReCordRep = patientReCordRep;
           _wardArea = wardArea;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public  async  Task<List<PatientReCordDTO>> ShowPatientReCord()
        {



            //var patients = _patientRep.GetAll().WhereIF(!string.IsNullOrEmpty(NursingUnit), m => m.NursingUnit == NursingUnit);
            //var patients = _patientRep.GetAll().Where(x => x.NursingUnit == NursingUnit);

            var showPatient = from a in _patientRep.GetAll()
                              join b in _patientReCordRep.GetAll() on a.PatientCode equals b.PatientCode
                              join c in _wardArea.GetAll () on a.WardAreaCode equals c.WardAreaCode
                              select new PatientReCordDTO
                              {
                                  Id = b.Id,
                                  PatientCode = a.PatientCode,
                                  Address = a.Address,
                                  Age = a.Age,
                                  BedCode = a.BedCode,
                                  Breathe = b.Breathe,
                                  Diagnosis = a.Diagnosis,
                                  IDNo = a.IDNo,
                                  WardAreaCode = a.WardAreaCode,
                                  HeartRate = b.HeartRate,
                                  MaxBP = b.MaxBP,
                                  Measures = b.Measures,
                                  MinBP = b.MinBP,
                                  Name = a.Name,
                                  NursingUnit = a.NursingUnit,
                                  OfficeCode = a.OfficeCode,
                                  Oximetry = b.Oximetry,
                                  Phone = a.Phone,
                                  Rate = b.Rate,
                                  Sex = a.Sex,
                                  SignUrl = b.SignUrl,
                                  SOSName = a.SOSName,
                                  Temperature = b.Temperature,
                                  WardCode = a.WardCode,
                                  
                              };

            return await Task.FromResult(showPatient.ToList());
        }
    }
}
